// Tags:
#include <algorithm>
#include <cctype>
#include <cstdio>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 1e5 + 5;
int m, cnt;
int f[N], pri[N];
bool vis[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("zgg.in", "r", stdin);
  freopen("zgg.out", "w", stdout);
#endif
#endif

  f[1] = 1;
  for (int i = 2; i < N; ++i) {
    if (!vis[i]) {
      pri[++cnt] = i;
      f[i] = f[i - 1];
    }
    for (int j = 1; j <= cnt && pri[j] * i < N; ++j) {
      vis[pri[j] * i] = true;
      f[pri[j] * i] = f[pri[j]] + f[i];
      if (i % pri[j] == 0) break;
    }
  }
  int t = 0;
  long long max = 0;
  read(t);
  while (t--) {
    read(m);
    long long ans = 1, p, q;
    for (int i = 1; i <= m; ++i) {
      read(p), read(q);
      if (!(p & 1)) --ans;
      ans += f[p] * q;
    }
    printf("%lld\n", ans);
    max = std::max(max, ans);
  }
  printf("%lld", max);
  return 0;
}